#include<iostream>
#include<algorithm>

using namespace std;
  
const int N = 1e5 + 10;
typedef long long ll;

struct node
{
	ll b;
	ll t;
}a[N];

bool cmp(  node& s1,  node& s2)
{
	return s1.t * s2.b < s2.t * s1.b;
}

int main()
{
	int n; cin >> n;
      
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i].t >> a[i].b;
	}

	sort(a + 1, a + 1 + n, cmp);

	ll ret = 0; ll time = 0;
	for (int i = 1; i <= n; i++)
	{
		ret += a[i].b * time;
		time += 2*a[i].t;
	}
	cout << ret;
	return 0;
}
